using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using DevExpress.XtraEditors;
using Wolfut.MirageEE.UI.UIBaseComponents;
using Wolfut.MirageEE.Domain.CommonUtilities;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraBars;

namespace Wolfut.MirageEE.UI.UI.Common
{
    public partial class CodeRuleForm : MirageEEFormBase
    {
        #region Init
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.barButtonItemAllDelete.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemAllDelete_ItemClick);
            this.barButtonItemExcel.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemExcel_ItemClick);
            this.barButtonItemHtml.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemHtml_ItemClick);
            this.barButtonItemText.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.barButtonItemText_ItemClick);

        }
        public CodeRuleForm()
        {
            InitializeComponent();
            this.Init();
        }
        private void Init()
        {
            ucCustomer.CodeFlag = Constant.CodeRuleConst.CUSTOMER;
            ucDepartment.CodeFlag = Constant.CodeRuleConst.DEPARTMENT;
            ucEmployee.CodeFlag = Constant.CodeRuleConst.EMPLOYEE;
            ucProduct.CodeFlag = Constant.CodeRuleConst.PRODUCT;
            ucProject.CodeFlag = Constant.CodeRuleConst.PROJECT;
            ucSupplier.CodeFlag = Constant.CodeRuleConst.SUPPLIER;
            foreach (Control item in tabCodeRules.TabPages)
            {
                foreach (Control subItem in item.Controls)
                {
                    if (subItem is UserCodeRulesControl)
                    {
                        item.Text = Constant.CodeRuleConst.GetCodeRuleFlagName(((UserCodeRulesControl)subItem).CodeFlag);
                        break;
                    }
                }
            }
        }
        #endregion

        #region Copy
        private UserCodeRulesControl SelectedPageFindControl()
        {
            foreach (Control item in tabCodeRules.SelectedTabPage.Controls)
            {
                if (item is UserCodeRulesControl)
                {
                    return (UserCodeRulesControl)item;
                }
            }
            return null;
        }
        private void barButtonItemExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag)); 
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_EXCEL, SelectedPageFindControl().GridCodeRule);
        }
        private void barButtonItemHtml_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag)); 
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_HTML, SelectedPageFindControl().GridCodeRule);
        }
        private void barButtonItemText_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.exportPrintHelper.SetExportFileName(Constant.CodeRuleConst.GetCodeRuleFlagName(SelectedPageFindControl().CodeFlag)); 
            exportPrintHelper.Export(Constant.ExportPrintOptions.EXPORT_TO_TEXT, SelectedPageFindControl().GridCodeRule);
        }
        private void barButtonItemAllDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.SelectedPageFindControl().OnAllDeleted(e);
        }
        #endregion

        #region Base
        private void simpleButtonClose_Click(object sender, EventArgs e)
        {
            base.CloseMe();
        }
        private void simpleButtonHelp_Click(object sender, EventArgs e)
        {
            base.HelpMe(this.Name);
        }
        #endregion
    }
}